<?php
namespace app\boss\controller;
use app\boss\service\Boss;
use app\boss\service\User;
use think\Cookie;

/**
 * Created by PhpStorm.
 * User: zd
 * Date: 2019/1/17
 * Time: 15:45
 */
class Index extends BaseController
{


    public function login($corpid){
        $url = $this->request->url(true);
        $appid =$this->request->param('corpid');
        $this->appid = $appid;
        $user = new User();
        $user = $user->isLogin($appid,$url);
        if ($user->error_code == 200){
            if ($user->content->ai_power == 'off'){
                $this->error('你没有此应用权限');
            }else{
                $this->redirect("Index/index",['corpid'=>$appid],302);
            }
        }else{
            $this->error('你没有此应用权限');
        }
    }

    /**
     * 首页
     * @return string
     */
    public function index(){
        $token = Cookie::get('BOSS_TT');
        $appid =$this->request->param('corpid');
        $url = $this->request->url(true);
        $config = $this->getWxConfig($url,$token,$appid);
        $this->assign('token',$token);
        $this->assign('config',$config);
        $this->assign('corpid',$appid);
        return $this->view->fetch('index/boss');
    }

    public function gotoParticulars(){

    }
    /**
     * 所有统计数据
     * @param $type
     * @param $token
     * @param $timeInfo
     * @return \think\response\Json
     */
    public function getAllDara($token,$time,$type){
        $server = new Boss();
        $list = $server->getAllDara(  Cookie::get('BOSS_TT'),$time,$type);
        if (empty($list)){
            $data=['data'=>''];
        }else{
            $data=['data'=>$list];
        }
        return json($data);
    }

    /**
     * 所有统计数据
     * @param $type
     * @param $token
     * @param $timeInfo
     * @return \think\response\Json
     */
    public function getAllRateNum($token,$rate){
        $server = new Boss();
        $list = $server->getAllRateNum( Cookie::get('BOSS_TT'),$rate);
        if (empty($list)){
            $data=['data'=>''];
        }else{
            $data=['data'=>$list];
        }
        return json($data);
    }
    /**
     * 所有订单统计
     * @param $type
     * @param $token
     * @param $timeInfo
     * @return \think\response\Json
     */
    public function getAllOrders($token,$time){
        $server = new Boss();
        $list = $server->getAllOrders( Cookie::get('BOSS_TT'),$time);
        if (empty($list)){
            $data=['data'=>''];
        }else{
            $data=['data'=>$list];
        }
        return json($data);
    }
    /**
     * 获取所有跟进信息
     * @param $type
     * @param $token
     * @param $timeInfo
     * @return \think\response\Json
     */
    public function getAllFollowData($token,$time){
        $server = new Boss();
        $list = $server->getAllFollowData( Cookie::get('BOSS_TT'),$time);
        if (empty($list)){
            $data=['data'=>''];
        }else{
            $data=['data'=>$list];
        }
        return json($data);
    }
    /**
     * 新增客户数
     * @param $type
     * @param $token
     * @param $timeInfo
     * @return \think\response\Json
     */
    public function getUserNum($token,$time){
        $server = new Boss();
        $list = $server->getUserNum( Cookie::get('BOSS_TT'),$time);
        if (empty($list)){
            $data=['data'=>''];
        }else{
            $data=['data'=>$list];
        }
        return json($data);
    }
    /**
     * 所有统计数据
     * @param $type
     * @param $token
     * @param $timeInfo
     * @return \think\response\Json
     */
    public function getAllBehaviorData($token){
        $server = new Boss();
        $list = $server->getAllBehaviorData( Cookie::get('BOSS_TT'));
        if (empty($list)){
            $data=['data'=>''];
        }else{
            $data=['data'=>$list];
        }
        return json($data);
    }
    /**
     * 所有活跃度统计
     * @param $type
     * @param $token
     * @param $timeInfo
     * @return \think\response\Json
     */
    public function getAllActiveData($token,$time){
        $server = new Boss();
        $list = $server->getAllActiveData( Cookie::get('BOSS_TT'),$time);
        if (empty($list)){
            $data=['data'=>''];
        }else{
            $data=['data'=>$list];
        }
        return json($data);
    }

    /**
     * 交互量统计
     * @param $type
     * @param $token
     * @param $timeInfo
     * @return \think\response\Json
     */
    public function getAllInteractionData($token){
        $server = new Boss();
        $list = $server->getAllInteractionData( Cookie::get('BOSS_TT'));
        if (empty($list)){
            $data=['data'=>''];
        }else{
            $data=['data'=>$list];
        }
        return json($data);
    }

    /**
     * 用户条件排序
     * @param $token
     * @param $confition
     * @param $num
     * @return \think\response\Json
     */
    public function getUserByCondition($token,$confition,$num){
        $server = new Boss();
        $list = $server->getUserByCondition( Cookie::get('BOSS_TT'),$confition,$num);
        if (empty($list)){
            $data=['data'=>''];
        }else{
            $data=['data'=>$list];
        }
        return json($data);
    }

    /**
     * 用户成交率区间排序
     * @param $token
     * @param $begin
     * @param $end
     * @return \think\response\Json
     */
    public function getUserByRate($token,$begin,$end){
        $server = new Boss();
        $list = $server->getUserRateNUm( Cookie::get('BOSS_TT'),$begin,$end);
        if (empty($list)){
            $data=['data'=>''];
        }else{
            $data=['data'=>$list];
        }
        return json($data);
    }

    /**
     * 用户属性
     * @param $token
     * @param $confition
     * @param $num
     * @return \think\response\Json
     */
    public function getUserData($token,$id){
        $server = new Boss();
        $list = $server->getUserData( Cookie::get('BOSS_TT'),$id);
        if (empty($list)){
            $data=['data'=>''];
        }else{
            $data=['data'=>$list];
        }
        return json($data);
    }
}